package com.ucpaas.sms.util;

import com.hankcs.hanlp.HanLP;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 关键字匹配工具类（基于DFA实现）
 */

public class JsmsHanLPUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(JsmsHanLPUtils.class);

    /**
     * 繁转简
     *
     * @param traditionalChineseString 繁体中文
     * @return 简体中文
     */
    public static String convertToSimplifiedChinese(String traditionalChineseString){
        if(StringUtils.isNotBlank(traditionalChineseString)){
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < traditionalChineseString.length(); i++) {
                sb.append(HanLP.convertToSimplifiedChinese(String.valueOf(traditionalChineseString.charAt(i))));
            }
            return sb.toString(); //繁体转简体

        }
        return null;
    }
    /**
     * 简转繁
     *
     * @param simplifiedChineseString 简体中文
     * @return 繁体中文
     */
    public static String convertToTraditionalChinese(String simplifiedChineseString){
        if(StringUtils.isNotBlank(simplifiedChineseString)){
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < simplifiedChineseString.length(); i++) {
                sb.append(HanLP.convertToTraditionalChinese(String.valueOf(simplifiedChineseString.charAt(i))));
            }
            return sb.toString(); //简体转繁体

        }
        return null;
    }
}
